package Xiaofang;

import java.io.*;
import java.nio.charset.Charset;

public class Work07 {
    public void replacte(String fi1,String fi2){
        BufferedReader reader=null;
        BufferedWriter writer=null;
        try {
            FileInputStream fis=new FileInputStream(fi1);
            try {
                InputStreamReader is=new InputStreamReader(fis,"utf-8");
                try {
                    FileWriter fw=new FileWriter(fi2);
                    reader=new BufferedReader(is);
                    writer=new BufferedWriter(fw);
                    String line=null;
                    StringBuffer sb=new StringBuffer();
                    while ((line=reader.readLine())!=null){
                        sb.append(line);
                    }

                    String ns=sb.toString().replace("{danhao}","543534543");
                    ns=ns.replace("{weizhi}","家加权");
                    ns=ns.replace("{tiquma}","8888");
                    writer.write(ns);
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    try {
                        writer.close();
                        reader.close();
                        is.close();
                        fis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Work07 wo=new Work07();
        wo.replacte("D:\\Xiaofang\\wuliu. template","D:\\Xiaofang\\物流.txt");
        System.out.println(Charset.defaultCharset());
    }
}